//Copyright (C) 2009 Ron Coleman. Contact: ronncoleman@gmail.com
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 3 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this library; if not, write to the Free Software
//Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
package org.workplicity.cia.model;

import java.io.Serializable;
import org.workplicity.cia.util.WorkDate;

/**
 * This class is the base class for all repository entries.
 * @author Ron Coleman
 *
 */
public abstract class Entry implements Serializable {

    private static final long serialVersionUID = -4904520442182013306L;
    /**
     * Unique id generated by the repository when first inserted
     */
    protected Integer id = new Integer(-1);
    /**
     * Last update date set by the repository during insert or update
     */
    protected WorkDate updateDate;
    /**
     * Create user (key) id set by the application.
     */
    protected Integer createUserId = new Integer(-1);
    /**
     * Update user (key) id set by the application.
     */
    protected Integer updateUserId = new Integer(-1);
    /**
     * Create date set by this class on construction.
     */
    protected WorkDate createDate = new WorkDate(System.currentTimeMillis());

    /**
     * Class name used for json
     */
    protected String brand = null;

    /**
     * Constructor
     */
    protected Entry() {
        this.brand = this.getClass().getName();
    }

    /**
     * Gets the unique id for this entry
     * @return the id
     */
    public Integer getId() {
        return id;
    }

    /**
     * Tests of two entries are equal by unique id.
     * @param entry Entry
     * @return True or false
     */
    public boolean equals(Entry entry) {
//        return id.intValue() == entry.id.intValue();
        return id.equals(entry.id);
    }

    /**
     * Gets the update date.
     * @return the date
     */
    public WorkDate getUpdateDate() {
        return updateDate;
    }

    /**
     * Sets the update date
     * @param date the date to set
     */
    public void setUpdateDate(WorkDate date) {
        this.updateDate = date;
    }

    /**
     * Gets the create user id.
     * @return the createUserId
     */
    public Integer getCreateUserId() {
        return createUserId;
    }

    /**
     * Sets the create user id.
     * @param createUserId the createUserId to set
     */
    public void setCreateUserId(Integer createUserId) {
        this.createUserId = createUserId;
    }

    /**
     * Gets the create date.
     * @return the createDate
     */
    public WorkDate getCreateDate() {
        return createDate;
    }

    /**
     * Sets the create date.
     * @param createDate the createDate to set
     */
    public void setCreateDate(WorkDate createDate) {
        this.createDate = createDate;
    }

    /**
     * Sets the unique id.
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * Gets the updating user id.
     * @return updating user id
     */
    public Integer getUpdateUserId() {
        return updateUserId;
    }

    /**
     * Sets the updating user id.
     * @param updateUserId User id
     */
    public void setUpdateUserId(Integer updateUserId) {
        this.updateUserId = updateUserId;
    }

    /**
     * Gets the brand.
     * @return Brand name
     */
    public String getBrand() {
        return brand;
    }

    /**
     * Sets the brand.
     */
    public void setBrand(String brand) {
        this.brand = brand;
    }
}
